package com.fjnu.aspect;

import com.fjnu.annotation.ExceptionGlobalCatch;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 全局异常处理切面类
 * 处理被@ExceptionGlobalCatch注解标记的方法的异常
 */
@Aspect
@Component
public class GlobalExceptionAspect {
    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionAspect.class);

    @Around("@annotation(exceptionGlobalCatch)")
    public Object handleException(ProceedingJoinPoint joinPoint, ExceptionGlobalCatch exceptionGlobalCatch) throws Throwable {
        try {
            return joinPoint.proceed();
        } catch (Exception e) {
            logger.error("Exception occurred in method: " + joinPoint.getSignature().getName(), e);
            throw e;
        }
    }
}